<template>
	<el-dialog :title="userName+`的`+titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="综合评价" prop="status">
						<sc-select v-model="form.status" :params="{code:'evaluateStatus'}" :apiObj="$API.hr.hrDic.getHrDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="工作技能" prop="skillLevel">
						<el-rate
							v-model="form.skillLevel"
							allow-half
							show-score
							text-color="#ff9900"
							score-template="{value}">
						</el-rate>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="学习能力" prop="learnLevel">
						<el-rate
							v-model="form.learnLevel"
							allow-half
							show-score
							text-color="#ff9900"
							score-template="{value}">
						</el-rate>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="工作态度" prop="attitudeLevel">
						<el-rate
							v-model="form.attitudeLevel"
							allow-half
							show-score
							text-color="#ff9900"
							score-template="{value}">
						</el-rate>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明">
				<el-input v-model="form.remark" placeholder="备注说明" clearable maxlength="380" type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>
<script>

export default {
	emits: ['success', 'closed'],
	components: {
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			isShowMsg: false,
			mode: "add",
			btName: "保存",
			titleMap: {
				add: '领导评价',
				edit: '领导评价',
				show: '查看'
			},
			userName:'',
			form: {
				recordId:"",
				userId: '',
				status:'',
				skillLevel:2.5,
				learnLevel:2.5,
				attitudeLevel:2.5,
				remark:''
			},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			//加载树数据
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.hr.hrEvaluate.insertHrEvaluate.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.hr.hrEvaluate.updateHrEvaluate.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			if(this.mode=='add')
			{
				this.userName = data.userName
				this.form.userId = data.userId
			}else if(this.mode=="edit")
			{
				this.userName = data.userName
				this.form.recordId = data.recordId
				this.form.userId = data.userId
				this.form.status = data.status
				this.form.skillLevel = data.skillLevel
				this.form.learnLevel = data.learnLevel
				this.form.attitudeLevel = data.attitudeLevel
				this.form.remark = data.remark
			}

		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
